#!/usr/bin/env python3
"""基本使用示例

展示如何使用 auto_video 项目生成图片的基本用法。
"""

import sys
import os
from pathlib import Path

# 添加项目根目录到 Python 路径
project_root = Path(__file__).parent.parent
sys.path.insert(0, str(project_root))

from src.generators.text_to_image import TextToImage
from src.models.model_manager import get_model_manager
from src.utils.config import get_config
from src.utils.logger import setup_logging


def main():
    """主函数"""
    # 设置日志
    logger = setup_logging(level='INFO')
    logger.info("开始基本使用示例")
    
    try:
        # 1. 初始化配置
        config = get_config()
        logger.info("配置加载完成")
        
        # 2. 创建输出目录
        output_dir = Path("outputs")
        output_dir.mkdir(exist_ok=True)
        
        # 3. 初始化文字转图片生成器
        logger.info("初始化文字转图片生成器...")
        generator = TextToImage()
        
        # 4. 生成图片示例
        prompts = [
            "a beautiful sunset over the ocean",
            "a cute cat sitting on a windowsill",
            "a futuristic city with flying cars",
            "a peaceful forest with sunlight filtering through trees"
        ]
        
        for i, prompt in enumerate(prompts, 1):
            logger.info(f"生成第 {i} 张图片: {prompt}")
            
            # 生成图片
            image = generator.generate(
                prompt=prompt,
                width=512,
                height=512,
                num_inference_steps=20,
                guidance_scale=7.5
            )
            
            # 保存图片
            output_path = output_dir / f"example_{i:02d}.jpg"
            generator.save_image(image, output_path)
            
            logger.info(f"图片已保存到: {output_path}")
        
        logger.info("所有示例图片生成完成！")
        
    except Exception as e:
        logger.error(f"生成过程中出现错误: {e}")
        raise


if __name__ == "__main__":
    main()